package com.seehope.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.seehope.po.User;
import com.seehope.service.UserService;
import com.seehope.service.impl.UserServiceImpl;

/**
 * Servlet implementation class GetAddUserServlet
 */
@WebServlet(name = "GetAddUserServlet", urlPatterns = "/getAddUserServlet")
public class GetAddUserServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
    private UserService userService =new UserServiceImpl();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetAddUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		  String id= request.getParameter("id");
		  User user=null;
		  if(!"".equals(id)&&null!=id){
			  user =userService.getUserById(Integer.parseInt(id));
		  }
		  request.setAttribute("user", user);
		  request.getRequestDispatcher("/WEB-INF/jsp/addOrUpdateUser.jsp").forward(request, response);
	}

}
